﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.pessoa;

namespace Desktop.views.cruds.crudsPessoa.crudCliente
{
    public partial class MenuCliente : Form
    {
        private TelaInicial telaInicial;
        private Fachada fachada = new Fachada();
        private List<Cliente> listaClientes;
        private Cliente cliente = new Cliente();
                

        public MenuCliente(TelaInicial telaInicial)
        {
            InitializeComponent();
            
            this.telaInicial = telaInicial;
            telaInicial.Hide();            
        }


        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroCliente cadastroCliente = new CadastroCliente(this);
            cadastroCliente.ShowDialog();
        }


        private void buttonSair_Click(object sender, EventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuCliente_FormClosed(object sender, FormClosedEventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }


        private void MenuCliente_Load(object sender, EventArgs e)
        {
            this.carregarGridViewCliente();
        } 


        private void dataGridViewCliente_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
            DataGridViewRow row = this.dataGridViewCliente.Rows[e.RowIndex];
                
                cliente.Id = row.Cells[0].Value.ToString();
                cliente.Nome = row.Cells[1].Value.ToString();
                cliente.Sexo = row.Cells[2].Value.ToString();
                cliente.Idade = row.Cells[3].Value.ToString();
                cliente.Rg = row.Cells[4].Value.ToString();
                cliente.Cpf = row.Cells[5].Value.ToString();

                AlterarRemoverCliente alterar = new AlterarRemoverCliente(this, cliente);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewCliente() 
        {
            listaClientes = fachada.listarCliente();

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewCliente.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            dataGridViewCliente.DataSource = listaClientes;

            this.dataGridViewCliente.Columns[0].HeaderText = "ID";
            this.dataGridViewCliente.Columns[1].HeaderText = "NOME";
            this.dataGridViewCliente.Columns[2].HeaderText = "SEXO";
            this.dataGridViewCliente.Columns[3].HeaderText = "IDADE";
            this.dataGridViewCliente.Columns[4].HeaderText = "RG";
            this.dataGridViewCliente.Columns[5].HeaderText = "CPF";

        }

        
    }
}
